package com.tyler.batch;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: TylerZhong
 * @description:
 */
public class BatchProducer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("batchProducerGroup");
        producer.setNamesrvAddr("192.168.56.191:9876");
        producer.start();

        List<Message> messages = new ArrayList<>();
        messages.add(new Message("Order", "Tag", "OrderID001", "Hello world 0".getBytes()));
        messages.add(new Message("Order", "Tag", "OrderID002", "Hello world 1".getBytes()));
        messages.add(new Message("Order", "Tag", "OrderID003", "Hello world 2".getBytes()));
        producer.send(messages);

        producer.shutdown();
        System.out.println("producer started");
    }
}
